package com.cw.jeeyt.service.converter.facade;

import java.util.List;

import com.cw.jeeyt.service.bo.facade.FacadeInfoBo;
import com.cw.jeeyt.dao.model.facade.FacadeInfoDo;
import com.cw.lang.common.utils.CollectionUtil;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;

/**
 * 接口信息转换类
 *
 * @author chenw
 * @date 2019-11-02 14:16:40
 */
public class FacadeInfoConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static FacadeInfoBo do2Bo(FacadeInfoDo model) {
        if (model == null) {
            return null;
        }
        return FacadeInfoBo.builder()
            .id(model.getId())
            .docId(model.getDocId())
            .facadeCode(model.getFacadeCode())
            .facadeName(model.getFacadeName())
            .facadeRequestType(model.getFacadeRequestType())
            .facadeVersion(model.getFacadeVersion())
            .facadeUrl(model.getFacadeUrl())
            .operateType(model.getOperateType())
            .requests(model.getRequests())
            .responses(model.getResponses())
            .enums(model.getEnums())
            .useMethod(model.getUseMethod())
            .createBy(model.getCreateBy())
            .createDate(model.getCreateDate())
            .updateBy(model.getUpdateBy())
            .updateDate(model.getUpdateDate())
            .build();
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static FacadeInfoDo bo2Do(FacadeInfoBo bo) {
        if (bo == null) {
            return null;
        }
        FacadeInfoDo model = new FacadeInfoDo();
        model.setId(bo.getId());
        model.setDocId(bo.getDocId());
        model.setFacadeCode(bo.getFacadeCode());
        model.setFacadeName(bo.getFacadeName());
        model.setFacadeRequestType(bo.getFacadeRequestType());
        model.setFacadeVersion(bo.getFacadeVersion());
        model.setFacadeUrl(bo.getFacadeUrl());
        model.setOperateType(bo.getOperateType());
        model.setRequests(bo.getRequests());
        model.setResponses(bo.getResponses());
        model.setEnums(bo.getEnums());
        model.setUseMethod(bo.getUseMethod());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<FacadeInfoBo> doList2BoList(List<FacadeInfoDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return null;
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(),FacadeInfoConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<FacadeInfoDo> boList2DoList(List<FacadeInfoBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return null;
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(),FacadeInfoConverter::bo2Do));
    }

}
